const mongoose = require("mongoose");
const seatsModel = mongoose.model("seats");

module.exports = {
    getOne: async _id => await seatsModel.findOne({ theaterId: _id }),
    add: async seat => await seatsModel.create(seat),
    update: async (conditions, doc) => await seatsModel.updateOne(conditions, doc),
    get: async ({ page, limit }) => {
        limit = ~~limit;
        const result = {};
        result.total = await seatsModel.countDocuments();
        result.rows = await seatsModel.find().populate('theaterId').skip((page - 1) * limit).limit(limit).exec();
        return result;
    },
    delete: async t_id => await seatsModel.deleteOne({ theaterId: t_id }),
}